<?php
/**
 * 游戏引导师报名页面控制器
 */
class Gamer extends Base_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('gamer_model');
    }

    public function preregister()
    {
        $post = $this->input->post();
        if (!isset($post['userName'])) $this->error('error: lack username');
        else $username = trim($post['userName']);
        if (!isset($post['email'])) $this->error('error: lack email');
        else $email = trim($post['email']);
        if (!isset($post['phone'])) $this->error('error: lack phone');
        else $phone = trim($post['phone']);
        $data = array('userName'=>$username,'email'=>$email,'telNum'=>$phone,'created'=>time(),'changed'=>time());
        $res = $this->gamer_model->preregister($data);
        if ($res === false) $this->error('user existed');
        else $this->success($data);
    }

    public function getCityList()
    {
        $res = $this->gamer_model->getCityList();
        $this->success($res);
    }

    public function getAreaListBycity()
    {
        $post = $this->input->post();
        if (!isset($post['cityid'])) $this->error('error: lack cityid');
        else $cityid = $post['cityid'];
        $res = $this->gamer_model->getAreaListBycity($cityid);
        $this->success($res);
    }

    public function register()
    {
        $uid = $this->input->input_stream('uid');
        $userName = $this->input->input_stream('userName');
        $userGender = $this->input->input_stream('userGender');
        $telNum = $this->input->input_stream('telNum');
        $wx_num = $this->input->input_stream('wx_num');
        $email = $this->input->input_stream('email');
        $eduLevel = $this->input->input_stream('eduLevel');
        $career = $this->input->input_stream('career');
        $careerstatus = $this->input->input_stream('careerstatus');
        $cert = $this->input->input_stream('cert');
        $jobcity = $this->input->input_stream('jobcity');
        $jobarea = $this->input->input_stream('jobarea');
        $marriage = $this->input->input_stream('marriage');
        $childage = $this->input->input_stream('childage');
        $livecity = $this->input->input_stream('livecity');
        $livearea = $this->input->input_stream('livearea');
        $freetime = $this->input->input_stream('freetime');
        $experience = $this->input->input_stream('experience');
        $hobby = $this->input->input_stream('hobby');
        $reason = $this->input->input_stream('reason');
        $hope = $this->input->input_stream('hope');
        if (!isset($uid)||!isset($userName)||!isset($userGender)||!isset($telNum)||!isset($wx_num)||!isset($email)
            ||!isset($eduLevel)||!isset($career)||!isset($careerstatus)||!isset($cert)||!isset($jobcity)
            ||!isset($jobarea)||!isset($marriage)||!isset($childage)||!isset($livecity)||!isset($livearea)
            ||!isset($freetime)||!isset($experience)||!isset($hobby)||!isset($reason)||!isset($hope))
            $this->error('lack params');
        $gamerinfo = array('uid'=>(int)$uid,'userName'=>$userName,'userGender'=>$userGender,'eduLevel'=>(int)$eduLevel, 'career'=>$career,
            'careerstatus'=>(int)$careerstatus,'cert'=>$cert,'jobcity'=>(int)$jobcity,'jobarea'=>(int)$jobarea,'marriage'=>(int)$marriage,
            'childage'=>(int)$childage,'livecity'=>(int)$livecity,'livearea'=>(int)$livearea,'freetime'=>igbinary_serialize($freetime),'experience'=>$experience,
            'hobby'=>$hobby,'reason'=>$reason,'hope'=>$hope,'created'=>time(),'changed'=>time());
        $user = array('telNum'=>$telNum,'wx_num'=>$wx_num,'email'=>$email,'utype'=>'gamer');
        $res = $this->gamer_model->register(array('uid'=>(int)$uid),$user,$gamerinfo);
        if ($res) $this->success();
        else $this->error();
    }
}